/*
 * @Title: 反向拼团-票选优品
 * @Author: zhj
 * @Date:   2018-12-20
 * @Last Modified by:   zhj
 * @Last Modified time: 2018-12-20
 */
var dataInfo = new Object(),
	template = {
		init: function() {
			Vue.use(VueLazyload, {
				preLoad: 1.3,
				error: 'https://h5.meetao.com/img/product/init.png',
				loading: 'https://h5.meetao.com/img/product/init.png',
				attempt: 1
			});
			dataInfo.init = new Vue({
				el: '#app',
				data: {
					page: 2, //往期票选活动分页
					active:7,//最新活动期数
					onnumLoading: false, //票选优品是否下来加载
					loading: false, //是否上拉加载
					isLoading: false, //是否下拉加载
					finished: false,
					allData: false,
					thisNum: "", //选中当前期数
					numberList: [], //活动期数票选列表
					PastList: [], //往期票选活动列表
					stageList: [], //期数列表
					newstageList:[],//期数列表
					voteActivityMap:[],//当前活动信息
				},
				methods: {
					onLoad: function() { //更多票选优品上拉加载
						dataInfo.init.queryVoteActivityMoreList();
					},
					onNumberList: function() { //优品下拉加载
						dataInfo.init.numberList = [];
						setTimeout(function() {
							dataInfo.init.$toast('刷新成功');
							dataInfo.init.onnumLoading = false;
							dataInfo.init.getVoteForTheBestList();
						}, 500);
					},
					onRefresh: function() { //下拉刷新
						dataInfo.init.PastList = [];
						dataInfo.init.page = 2;
						setTimeout(function() {
							dataInfo.init.$toast('刷新成功');
							dataInfo.init.queryVoteActivityMoreList();
						}, 500);
					},
					init: function() { //重置
						dataInfo.init.queryVoteActivityMoreList();
						dataInfo.init.queryDefaultActivity();//获取票选活动期数
					},
					onRule:function(){//跳转规则
						window.location.href="../html/FPtRule.html";
					},
					onThisVoteDetails:function(num){//跳转该票选期详情
						window.location.href="../html/FPtVoteGoodsDetails.html?activityIssueNum="+num;
					},
					onVoteDetails:function(index){//跳转投票详情
						window.location.href="../html/FPtVoteDetails.html?voteItemCode="+dataInfo.init.numberList[index].code;
					},
					getThisNum: function(index,title) { //获取当前活动期数
						if(title=="更多"){
							dataInfo.init.queryVoteActivityMoreList();
						}else{
							dataInfo.init.thisNum=title.replace(/^[^\d]*(\d+)[^\d]*$/, "$1");
							dataInfo.init.getVoteForTheBestList();
						}
					},
					queryDefaultActivity: function() { //获取票选活动期数
						ajaxTemplate(addressTest + SERVICE.queryDefaultActivity, function(data) {
							if(data.tag == 0) {
								dataInfo.init.stageList = data.data.result;
								for(var i in dataInfo.init.stageList){
									dataInfo.init.newstageList.push(dataInfo.init.stageList[i].activityIssueNum);
								}
								dataInfo.init.thisNum = dataInfo.init.newstageList[dataInfo.init.newstageList.length-1];
								dataInfo.init.getVoteForTheBestList();//获取票选优品的列表
							} else {

							}
						}, {});
					},
					queryVoteActivityMoreList: function() { //获取更多的票选优品商品列表
						ajaxTemplate(addressTest + SERVICE.queryVoteActivityMoreList, function(data) {
							if(data.tag == 0) {
								dataInfo.init.PastList =dataInfo.init.PastList.concat(data.data.result);
								if(data.data.result.length < 7) {
									console.log("无数据");
									dataInfo.init.finished = true;
									dataInfo.init.allData = true;
								} else {
									console.log("有数据");
									dataInfo.init.finished = false;
								}
								dataInfo.init.loading = false;
								dataInfo.init.isLoading = false;
							} else {
								dataInfo.init.loading = false;
								dataInfo.init.finished = true;
								dataInfo.init.allData = true;
							}
						}, {
							page: dataInfo.init.page++
						});
					},
					getVoteForTheBestList: function() { //获取票选优品的列表
						console.log(dataInfo.init.thisNum);
						ajaxTemplate(addressTest + SERVICE.getVoteForTheBestList, function(data) {
							if(data.tag == 0) {
								console.log(data);
								dataInfo.init.voteActivityMap = data.data.result.voteActivityMap;
								dataInfo.init.numberList = data.data.result.list;
								shareInfo.activityIssueNum = dataInfo.init.thisNum;
							} else {

							}
						}, {
							userId: userId,
							voteActivityIssueNum: dataInfo.init.thisNum
						});
					},
				},
			});
			dataInfo.init.init();
		}
	};
template.init();